import { makeAutoObservable } from 'mobx';
import { RecordKeys, Storage } from './storage';
import i18n from '~/i18n/languages';


type LANGUAGE = 'zh' | 'en';

interface app {
    netWorkConnected: boolean // 网络连接状态
    netWorkType: string // 网络连接类型
    language: LANGUAGE // 语言
}


class AppStore {
    app = {
        netWorkConnected: false,
        netWorkType: 'none',
        language: 'zh',
    } as app;
    constructor() {
        makeAutoObservable(this);
    }

    // 切换语言
    switchLanguage(language: 'zh' | 'en') {
        this.app.language = language
        Storage.setItem(RecordKeys.language, language);
        i18n.changeLanguage(language)
    }

    // 检测网络状态
    changeNetWork(type, isConnect) {
        this.app.netWorkType = type
        this.app.netWorkConnected = isConnect
    }
    // app提醒
    appUpdateNotice(status) {
        Storage.setItem(RecordKeys.updateApp, status)
    }
}



export default new AppStore();
